package com.example.test.util;

import lombok.extern.java.Log;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @ClassName: 林文峰
 * @Author Administrator
 * @Date 2020/6/18 0018
 */
@Log
public class FileUp {

	/**
	 * 上传文件
	 * @Author: 林文峰 
	 * @Date 2020/6/22 0022 19:01
	 */
	public static String fileUpload(MultipartFile file,String path){
		String last = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
		String fileName = "\\测试文件4";
		File file1 = new File(path+fileName+last);
		try {
			if (file1.exists()){
				System.out.println(file1.exists()+":"+file1.getName());
				log.info("创建文件");
				boolean newFile = file1.createNewFile();
				System.out.println(newFile);
			}
			file.transferTo(file1);
		} catch (IOException e) {
			e.printStackTrace();
			return "上传失败";
		}
		return path+fileName+last;
	}
}
